package org.dslmagic.holder;

import java.util.Map;

import org.dslmagic.dsl.Dsl;
import org.dslmagic.util.Code;

public class ClassHolder<T> {

	private final Class<T> cinterface;

	public ClassHolder(Class<T> cinterface) {
		this.cinterface = cinterface;
	}

	public <IT> T def(Dsl dsl) {
		return def(null, new Dsl[] { dsl });
	}

	public <IT> T def(String methodName, Dsl dsl) {
		return def(new String[] { methodName }, new Dsl[] { dsl });
	}

	@SuppressWarnings("unchecked")
	public <IT> T def(String[] methodNames, Dsl[] dsls) {
		Map<String, Dsl> implementations = Code.implementations(cinterface,
				methodNames, dsls);
		return (T) Code.define(null, cinterface, implementations);
	}
}
